package com.lzq.model.visitor.doubledispatch;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2022/11/29 15:32
 * @updateUser : modify
 * @updateTime : 2022/11/29 15:32
 * @updateRemark : 双分派
 */
public class Test {
    public static void main(String[] args) {
        Animal a = new Animal();
        Animal d = new Dog();
        Animal c = new Cat();

        Execute exe = new Execute();
        a.accept(exe);
        d.accept(exe);
        c.accept(exe);
    }
}

class Animal {
    public void accept(Execute exe) {
        exe.execute(this);
    }
}

class Dog extends Animal {
    public void accept(Execute exe) {
        exe.execute(this);
    }
}

class Cat extends Animal {
    public void accept(Execute exe) {
        exe.execute(this);
    }
}

class Execute {
    public void execute(Animal a) {
        System.out.println("animal");
    }

    public void execute(Dog d) {
        System.out.println("dog");
    }

    public void execute(Cat c) {
        System.out.println("cat");
    }
}
